package com.gopay.common.cps.dao.wallet.activity.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.classic.Session;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.wallet.activity.WaActivityRiddleAnswerDao;
import com.gopay.common.domain.dps.WaActivityRiddleAnswer;
/**
 * 
 * @author dps
 *
 */
@Repository("waActivityRiddleAnswerDao")
public class WaActivityRiddleAnswerDaoImpl extends BaseDAOImpl<WaActivityRiddleAnswer, Serializable> implements WaActivityRiddleAnswerDao{

	
	@Override
	public boolean saveAllRiddleAnswers(List<WaActivityRiddleAnswer> list) {
		boolean result=true;
		if(list!=null&&list.size()>0){
			Session session=null;
			try{
				session=super.hibernateTemplate.getSessionFactory().openSession();
				session.beginTransaction();
				for(int i=0;i<list.size();i++){
					super.save(list.get(i));
					if (i % 10 == 0) {  
	                    session.flush();  
	                    session.clear();  
	                }
				}
				session.getTransaction().commit(); // 提交事物  
			}catch(Exception e){
				e.printStackTrace();
				result=false;
				session.getTransaction().rollback();
			}finally{
				session.close();
			}
		}
		return result;
	}
	
}
